package com.yi.zsb.controller;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.yi.service.ws.IStudentWs;
import com.yi.service.ws.Student;
import com.yi.service.ws.StudentException;
import com.yi.service.ws.StudentException_Exception;

@Controller
public class StudentController {

	private IStudentWs studentWs ;

	public IStudentWs getStudentWs() {
		return studentWs;
	}

	@Inject
	public void setStudentWs(IStudentWs studentWs) {
		this.studentWs = studentWs;
	}

	@RequestMapping(value="/add" , method=RequestMethod.GET)
	public String add(){
		return "add" ;
	}
	
	@RequestMapping(value="/add" , method=RequestMethod.POST)    
	public String add(String xh , String name , String school , Model model){
		
	//	IStudentWs studentWs =  new StudentWs().getStudentPort();
		Student stu = null;
		try {
			stu = studentWs.getStudent(xh);
		} catch (Exception e) {   
			String mess = e.getMessage() ;
			model.addAttribute("error", mess);
			return "add";   
		}  
		if(stu == null){  
			model.addAttribute("error", "不是本校学生 ，不能报名！");
			return "add";
		}
		
		if(stu.getStatus() == 1){
			model.addAttribute("error", "该学生已经离校不能报名！");
			return "add";
		}
		
		/*List<RewardAndPubnish> re = studentWs.listRapByStu(xh);
		for(RewardAndPubnish r : re){
			// if(r.geti){}
		}*/   
		
		model.addAttribute("xh", xh);  
		model.addAttribute("name", stu.getName());
		model.addAttribute("school", school);
		
		return "success";
	}
}
